package cn.itcast.order.controller;

import cn.itcast.entity.Order;
import cn.itcast.entity.Product;
import cn.itcast.entity.User;
import cn.itcast.order.fegin.ProductFeginClient;
import cn.itcast.order.fegin.UserFeginClient;
import cn.itcast.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {

	@Autowired
	private OrderService orderService;

	@Autowired
	private ProductFeginClient productFeginClient;

	@Autowired
	private UserFeginClient userFeginClient;

	@GetMapping("/{id}")
	public Order findById(@PathVariable  Long id) {
		return orderService.findById(id);
	}

	@GetMapping("/buy/{id}")
	public Map order(@PathVariable  Long id) {
		Product product = productFeginClient.findById(id);
		User user = userFeginClient.findById(1l);
		Map map = new HashMap();
		map.put("user",user);
		map.put("product",product);
		return map;
	}
}
